﻿/*++
 * Copyright (c) DemeterSoft Corporation
 *
 * File Name:
 *     NavigationPart.cs
 *     
 * Abstract:
 *     导航面板，主要用于导航
 *
 * Revision History:
 *     08/29/2011    yliu
 *         创建文件
 * --*/
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using SmartSpace.Silverlight;
using SmartSpace.Silverlight.Shell.DefaultTheme.Controls;
using SmartSpace.Silverlight.Shell.DefaultTheme.Utils;

namespace SmartSpace.Silverlight.Shell.DefaultTheme
{
    /// <summary>
    /// 导航面板
    /// </summary>
    public partial class NavigatePanel : SlView, INavigatePanel
    {
        #region Variables

        /// <summary>
        /// 导航委托事件
        /// </summary>
        public event Action<bool> NavigationPanelCollapsed;

        public event NavigatingEventHandler Navigating;

        private NavigationPanellUtil _util;
        #endregion

        #region Constructors

        public NavigatePanel()
        {
            InitializeComponent();

            _ctlContainer.SwitchEffect = new VerticalSwitchEffect();

            _util = new NavigationPanellUtil(this._ctlBtnBack, _ctlContainer, _ctlNavigationMap);
            _ctlContainer.Attach(_util);
        }

        #endregion

        public void LoadNavigations(IEnumerable<SlNavigation> navigations, IEnumerable<SlShortcut> shortCuts)
        {
            List<SlNavigation> links = new List<SlNavigation>();
            foreach (SlNavigation model in navigations)
            {
                links.Add(model);
            }

            _ctlContainer.SwitchView(new NavigationPart(null, links, Navigate));
        }

        public SlView GetContentView()
        {
            return this;
        }

        protected void Navigate(object sender, NavigatingEventArgs e)
        {
            if (Navigating != null)
            {
                Navigating(sender, e);
            }
        }

        private void _ctlBtnBack_Click(object sender, RoutedEventArgs e)
        {
            _ctlContainer.GoBack();
        }
    }
}
